<?php require_once('Connections/online.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frm")) {
  $updateSQL = sprintf("UPDATE usuario SET rut=%s, nombre=%s, apellido_pat=%s, apellido_mat=%s, telefono=%s, direccion=%s, email=%s, tipo=%s, clave=%s WHERE id_usuario=%s",
                       GetSQLValueString($_POST['rut'], "text"),
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['apellido_pat'], "text"),
                       GetSQLValueString($_POST['apellido_mat'], "text"),
                       GetSQLValueString($_POST['telefono'], "int"),
                       GetSQLValueString($_POST['direccion'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['tipo'], "text"),
                       GetSQLValueString($_POST['clave'], "int"),
                       GetSQLValueString($_POST['id_usuario'], "int"));

  mysql_select_db($database_online, $online);
  $Result1 = mysql_query($updateSQL, $online) or die(mysql_error());

  $updateGoTo = "modificar_usuarios.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
?>
<?php
include ("conexion.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Usuarios</title>
    <link rel="stylesheet" href="jquery.ui.all.css">
<link rel="stylesheet" href="demos.css">
<link rel="stylesheet" href="jquery.ui.datepicker.css">
<link rel="stylesheet" href="css/jquery-ui-1.8.20.custom.css">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.20.custom.min.js"></script>
<script src="ui/jquery.ui.core.js"></script>
	<script src="ui/jquery.ui.widget.js"></script>
	<script src="ui/jquery.ui.datepicker.js"></script>
	<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script>
	$(function() {
		$( "#calendario" ).datepicker();
	});
	</script>
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
    <style type="text/css">
<!--
.Estilo1 {color: #000080}
.Estilo2 {
	font-size: 36px;
	font-weight: bold;
	font-family: Geneva, Arial, Helvetica, sans-serif;
}
-->
    </style>
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Header -->
<div id="header">
	<div class="shell">
		<!-- Logo + Top Nav -->
		<div id="top">
			<h1><a href="#">	<span class="Estilo2">VETERINARIA</span> PELUVETS</a></h1>
<div id="top-navigation">
				<a href="index.php"><strong>Cerrar</strong></a>
				
			</div>
		</div>
		<!-- End Logo + Top Nav -->
		
		<!-- Main Nav -->
		<div id="navigation">
		<ul id="nav">
			    <li><a href="categorias.php" ><span>Categoria</span></a>
                 <ul id="navi">
          
      </ul>
	            <li><a href="usuarios.php" class="active" ><span>Usuarios</span></a></li>	
	            <li><a href="productos.php"><span>Producto</span></a></li>
			
      </ul>
		</div>
</div>

<div id="container">
<div class="shell1">
		
		<!-- Small Nav -->
		<div class="small-nav"></div>
		<!-- End Small Nav -->
		
		<!-- Message OK -->
	  <!-- End Message OK -->		
		
	  <!-- Message Error -->
	  <!-- End Message Error -->
  <br />
		<!-- Main -->
		<div id="main">
			<div class="cl"></div>
			
			<div id="manten1">
				
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head3">
                      <h2 class="left">Modificar Usuarios&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </h2>
                      <div class="right"> <a href="usuarios.php">
                        <input type="submit" class="button" value="Eliminar" />
                      </a> </div>
				  </div>
					<!-- End Box Head -->	
                     
                     
 <?php
 
include "conexion.php";

 
$query="SELECT * FROM usuario ";
 
$result=mysql_query($query) or die("Error: ".mysql_error());
  
if(mysql_num_rows($result) > 0){
 
?>
                     <div class="table">
                     <table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
                              <th width="172"><div align="left">Codigo</div></th>
							  <th width="172"><div align="left">Rut</div></th>
                              <th width="253"><div align="left">Nombre</div></th>
                              <th width="253"><div align="center">Apellido Paterno</div></th>
                              <th width="172"><div align="left">Apellido Materno</div></th>
							  <th width="172"><div align="center">Telefono</div></th>
                              <th width="253"><div align="left">Direccion</div></th>
							  <th width="172"><div align="center">Email</div></th>
							  <th width="172"><div align="center">Tipo</div></th>
                              <th width="253"><div align="left">Clave</div></th>
                              <th width="223" class="ac"><div align="center">Modificar</div></th>
						  </tr>
<?php    
 
  while($Rs=mysql_fetch_array($result)) { 
      echo "<tr>".
      "<tr><td><center>".$Rs["id_usuario"]."</center></td>".
	  "<td>".$Rs["rut"]."</td>".
	  "<td>".$Rs["nombre"]."</td>".
	  "<td>".$Rs["apellido_pat"]."</td>".
	  "<td>".$Rs["apellido_mat"]."</td>".
	  "<td>".$Rs["telefono"]."</td>".
	  "<td>".$Rs["direccion"]."</td>".
	  "<td>".$Rs["email"]."</td>".
	  "<td>".$Rs["tipo"]."</td>".
	  "<td><center>".$Rs["clave"]."</center></td>".
      "<td><a href=./modificar_usuarios.php?id_usuario=".$Rs["id_usuario"]." class='ico del'>Modificar</a></td>".
    "</tr>";
				  
}
 
}else{
 
echo "No hay usuarios registradas para listar";
 
}
 
?>
                     
    </table> 

    
      
    </div>    
                     
                     
           
						</table>
                        
                        
						<!-- Pagging -->
						
				</div>
	  </div>
	</div>
        		<!-- Pagging -->
						
		  </div>
	  </div>
        
        
</div>
</div>
<div id="fin">
	<div class="shell1">
		
        
            
    <div id="sidebar">
				
				<!-- Box -->
				<div class="box">
				
					
					<div class="box-content">
    
    
           <?php
 
include "conexion.php";

 
if(isset($_POST["submit"])){
 
    $query = "UPDATE usuario SET id_usuario='".$_POST["id_usuario"]."', ".
	    "rut='".$_POST["rut"]."', ".
        "nombre='".$_POST["nombre"]."', ".
        "apellido_pat='".$_POST["apellido_pat"]."' , ".
		"apellido_mat='".$_POST["apellido_mat"]."' , ".
		"telefono='".$_POST["telefono"]."', ".
        "direccion='".$_POST["direccion"]."', ".
        "email='".$_POST["email"]."', ".     
        "tipo='".$_POST["tipo"]."', ".
        "clave='".$_POST["clave"]."'WHERE id_usuario=".$_POST["id_usuario"];
    mysql_query($query) or die("Error: ".mysql_error());
    echo "Id.$id_usuario ha sido modificado<br>";
 
}else{

 
    $id_usuario=$_GET['id_usuario'];
    $query="SELECT * FROM usuario WHERE id_usuario='".$id_usuario."'";
    $result=mysql_query($query) or die("Error: ".mysql_error());

 
    if(mysql_num_rows($result) > 0){
 
    while($Rs=mysql_fetch_array($result)) {
 
    ?>
 <div class="table">
    <form  method=POST name=frm action="<?php echo $editFormAction; ?>">
        <table width="307">
       <tr><th colspan="2"><span class="Estilo1"><h3 align="center">Modificar Registro</h3></span></th>
       </tr>
      <tr>
        <td width="86" class="Estilo23 Estilo1">Codigo</td>
        <td width="209"><span id="sprytextfield1">
          <input name='id_usuario'  type='text' maxlength='2' value="<?php echo $Rs['id_usuario']; ?>" readonly='true'>
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
        <tr>
        <td class="Estilo23 Estilo1">Rut</td>
        <td><span id="sprytextfield2">
          <input name='rut'  type='text' maxlength='50' value="<?php echo $Rs['rut']; ?>">
          <span class="textfieldRequiredMsg">obligatorio</span></span></td>
        </tr>
      <tr>
        <td class="Estilo23 Estilo1">Nombre</td>
        <td><span id="sprytextfield3">
          <input name='nombre'  type='text' maxlength='50' value="<?php echo $Rs['nombre']; ?>">
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
        <tr>
        <td width="86" class="Estilo23 Estilo1">Apellido Paterno</td>
        <td width="209"><span id="sprytextfield4">
          <input name='apellido_pat'  type='text' maxlength='20' value="<?php echo $Rs['apellido_pat']; ?>">
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
		
		 <tr>
        <td width="86" class="Estilo23 Estilo1">Apellido Materno</td>
        <td width="209"><span id="sprytextfield4">
          <input name='apellido_mat'  type='text' maxlength='20' value="<?php echo $Rs['apellido_mat']; ?>">
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
		
		<tr>
        <td class="Estilo23 Estilo1">Telefono</td>
        <td><span id="sprytextfield7">
          <input name='telefono'  type='text' maxlength='8' value="<?php echo $Rs['telefono']; ?>">
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
    
      <tr>
        <td class="Estilo23 Estilo1">Direccion</td>
        <td><span id="sprytextfield5">
          <input name='direccion'  type='text' maxlength='50' value="<?php echo $Rs['direccion']; ?>">
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
        <tr>
        <td width="86" class="Estilo23 Estilo1">Email</td>
        <td width="209"><span id="sprytextfield6">
          <input name='email'  type='text' maxlength='20' value="<?php echo $Rs['email']; ?>">
          <span class="textfieldRequiredMsg">Obligatorio</span></span></td>
        </tr>
      
        <tr>
        <td width="86" class="Estilo23 Estilo1">tipo</td>
        <td width="209"><select name="tipo" id="tipo">
          <option value="administrador">Administrador</option>
          <option value="cliente">Cliente</option>
        </select></td>
        </tr>
      <tr>
        <td class="Estilo23 Estilo1">Clave</td>
        <td><input name='clave' type="password" maxlength='6' value="<?php echo $Rs['clave']; ?>"></td>
        </tr>
        
      
      <tr>
        <td>&nbsp;</td>
        <td><input name='submit' class="button" type='submit' value='Enviar'></td>
      </tr>
    </table>
        <input type="hidden" name="MM_update" value="frm">
    </form>
 
    <?php
    }
 
    }else{
        echo "No fué posible realizar la operación solicitada ".$id_usuario;
    }
}

 
?>
 
</table>
</form>
        
        
	</div>
</div>
	
                                        <script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7");
//-->
</script>
</body>
</html>